'use strict';

const Hapi = require('hapi');


// Create a server with a host and port
const server = Hapi.server({
    host: '172.16.181.109',
    // host: '192.168.0.104',
    port: 8000
});


const route = require('./routes');
// Add the server routes
route.forEach(function(api) {
    server.route(api);
});


const models = require('./models');
//Connect database
var initDb = function() {
    var sequelize = models.sequelize;
    //Determine if the database connection is successful
    sequelize.sync({ force: false }).then(function() {
        console.log("connection database successed");
    }).catch(function(err) {
        console.log("connection failed due to error: %s", err);
    });
};
initDb();

// Export the server to be required elsewhere.
module.exports = server;